clear all 
set more off

global mydir "C:\XYZ" // set working directory

cd "$mydir\data\demographics"
set matsize 11000
set maxvar 32700

**Build demographics, race and medhhinc for block level at 2000 and 2010 in 1 file
import delimited raw\block2010_CA_area.csv, clear
gen year=2010
rename geoid10 bgeoid
rename aland10 aland
rename awater10 awater
rename intptlat10 blat
rename intptlon10 blon
rename countyfp10 cntyid
keep year cntyid bgeoid bggeoid aland awater blat blon
sort bgeoid
save block_demographics_2010_CA, replace

**merge with 2010 demographics
import delimited raw\block2010_CA_pop_race.csv, clear 
sort bgeoid
keep bgeoid state statea county tracta pop white black asian hispanic house ochouse hh
tempfile tmp
save `tmp', replace
use block_demographics_2010_CA, clear
merge 1:1 bgeoid using `tmp'
erase `tmp'
drop _merge // _merge==3 for all

**merge med hh income
sort bggeoid
save block_demographics_2010_CA, replace
use raw\blockgroup_demographics_2010_CA, clear
rename BGgeoid bggeoid
rename BG* *
sort bggeoid
keep bggeoid mdhhinc // incpcapita
tempfile tmp
save `tmp', replace
use block_demographics_2010_CA, clear
merge m:1 bggeoid using `tmp'
erase `tmp'
drop _merge // _merge==3 for all
save block_demographics_2010_CA, replace
